package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.module;
import com.iwhalecloud.bss.kite.client.vo.scene.CommonAttrModuleVO;
import com.iwhalecloud.bss.kite.client.vo.scene.ModuleVO;
import com.iwhalecloud.bss.kite.client.vo.scene.SceneVO;
import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.cucc.web.service.accept.vo.CuccCommonAttrModuleVO;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.web.service.accept.bo.AcceptContext;
import com.iwhalecloud.bss.kite.web.service.accept.bo.SceneModule;
import com.iwhalecloud.bss.kite.web.service.accept.handler.module.CommonAttrModuleHandler;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
 * <Description>业务变更相关模块-添加模块说明 <br>
 * @author chenkaiwen<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2020-11-25<br>
 * @see com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.module.CuccCommonAttrModuleHandler <br>
 */
@Service
public class CuccCommonAttrModuleHandler extends CommonAttrModuleHandler {

    @Override
    public List<? extends ModuleVO> execute(AcceptContext context, SceneModule sceneModule) {
        super.execute(context, sceneModule);
        String layoutPage = sceneModule.getKiteModule().getLayoutPage();
        String serviceOfferId = context.getAcceptRequest().getServiceOfferId();
        String moduleId = sceneModule.getKiteModule().getModuleId();
        String desc = DcPublicCache.getCodea(serviceOfferId, moduleId);
        SceneVO sceneVO = context.getSceneVo();
        Map<String,Object> defCommonAttr = sceneVO.getCommonInfo();
        CommonAttrModuleVO commonAttrModuleVO = (CommonAttrModuleVO)defCommonAttr.get(layoutPage);
        CuccCommonAttrModuleVO cuccCommonAttrModuleVO = KiteBeanUtils.transform(commonAttrModuleVO, CuccCommonAttrModuleVO.class);
        cuccCommonAttrModuleVO.setDesc(desc);
        defCommonAttr.put(layoutPage, cuccCommonAttrModuleVO);
        return  Collections.singletonList(cuccCommonAttrModuleVO);
    }

    @Override
    public List<ModuleVO> previewSceneVo(AcceptContext context, SceneModule sceneModule) {
        super.previewSceneVo(context, sceneModule);
        String layoutPage = sceneModule.getKiteModule().getLayoutPage();
        String serviceOfferId = context.getAcceptRequest().getServiceOfferId();
        String moduleId = sceneModule.getKiteModule().getModuleId();
        String desc = DcPublicCache.getCodea(serviceOfferId, moduleId);
        SceneVO sceneVO = context.getSceneVo();
        Map<String, Object> defCommonAttr = sceneVO.getCommonInfo();
        CommonAttrModuleVO commonAttrModuleVO = (CommonAttrModuleVO) defCommonAttr.get(layoutPage);
        CuccCommonAttrModuleVO cuccCommonAttrModuleVO = KiteBeanUtils.transform(commonAttrModuleVO, CuccCommonAttrModuleVO.class);
        cuccCommonAttrModuleVO.setDesc(desc);
        defCommonAttr.put(layoutPage, cuccCommonAttrModuleVO);
        return Collections.singletonList(cuccCommonAttrModuleVO);
    }

    @Override
    public CommonAttrModuleVO dealExecuteSpecialAttr(AcceptContext context, SceneModule sceneModule, CommonAttrModuleVO defCommonAttrInfoVO) {
        return defCommonAttrInfoVO;
    }

    @Override
    public CommonAttrModuleVO dealPreviewSpecialAttr(AcceptContext context, SceneModule sceneModule, CommonAttrModuleVO defCommonAttrInfoVO) {
        return defCommonAttrInfoVO;
    }
}
